/*
 * sum.c
 *
 * Code generation for function 'sum'
 *
 */

/* Include files */
#include "rt_nonfinite.h"
#include "master_function_v4.h"
#include "sum.h"
#include "master_function_v4_mexutil.h"
#include "master_function_v4_data.h"

/* Function Definitions */
real_T sum(const emlrtStack *sp, const real_T x_data[], const int32_T x_size[2])
{
  real_T y;
  boolean_T p;
  boolean_T b_p;
  int32_T i;
  int32_T exitg1;
  const mxArray *b_y;
  static const int32_T iv4[2] = { 1, 30 };

  const mxArray *m1;
  char_T cv8[30];
  static const char_T cv9[30] = { 'C', 'o', 'd', 'e', 'r', ':', 't', 'o', 'o',
    'l', 'b', 'o', 'x', ':', 's', 'u', 'm', '_', 's', 'p', 'e', 'c', 'i', 'a',
    'l', 'E', 'm', 'p', 't', 'y' };

  const mxArray *c_y;
  static const int32_T iv5[2] = { 1, 36 };

  char_T cv10[36];
  static const char_T cv11[36] = { 'C', 'o', 'd', 'e', 'r', ':', 't', 'o', 'o',
    'l', 'b', 'o', 'x', ':', 'a', 'u', 't', 'o', 'D', 'i', 'm', 'I', 'n', 'c',
    'o', 'm', 'p', 'a', 't', 'i', 'b', 'i', 'l', 'i', 't', 'y' };

  emlrtStack st;
  emlrtStack b_st;
  st.prev = sp;
  st.tls = sp->tls;
  b_st.prev = sp;
  b_st.tls = sp->tls;
  p = false;
  b_p = false;
  i = 0;
  do {
    exitg1 = 0;
    if (i < 2) {
      if (x_size[i] != 0) {
        exitg1 = 1;
      } else {
        i++;
      }
    } else {
      b_p = true;
      exitg1 = 1;
    }
  } while (exitg1 == 0);

  if (!b_p) {
  } else {
    p = true;
  }

  if (!p) {
  } else {
    b_y = NULL;
    m1 = emlrtCreateCharArray(2, iv4);
    for (i = 0; i < 30; i++) {
      cv8[i] = cv9[i];
    }

    emlrtInitCharArrayR2013a(sp, 30, m1, cv8);
    emlrtAssign(&b_y, m1);
    st.site = &m_emlrtRSI;
    b_st.site = &r_emlrtRSI;
    error(&st, message(&b_st, b_y, &b_emlrtMCI), &c_emlrtMCI);
  }

  if ((x_size[1] == 1) || (x_size[1] != 1)) {
    p = true;
  } else {
    p = false;
  }

  if (p) {
  } else {
    c_y = NULL;
    m1 = emlrtCreateCharArray(2, iv5);
    for (i = 0; i < 36; i++) {
      cv10[i] = cv11[i];
    }

    emlrtInitCharArrayR2013a(sp, 36, m1, cv10);
    emlrtAssign(&c_y, m1);
    st.site = &l_emlrtRSI;
    b_st.site = &q_emlrtRSI;
    error(&st, message(&b_st, c_y, &d_emlrtMCI), &e_emlrtMCI);
  }

  if (x_size[1] == 0) {
    y = 0.0;
  } else {
    y = x_data[0];
    for (i = 2; i <= x_size[1]; i++) {
      y += x_data[i - 1];
    }
  }

  return y;
}

/* End of code generation (sum.c) */
